﻿using System;
using System.Diagnostics;
using CPN.PJN.Silverlight.Common.Configuration;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace CPN.PJN.Common.Configuration.UnitTests
{
    [TestClass]
    public class Tests
    {
        public Uri ConfigurationUri
        {
            get
            {
                return new Uri(@"http://localhost:8888/clientbin/Silverlight.Core.xml", UriKind.RelativeOrAbsolute);
            }
        }

        [TestMethod]
        public void TestMethod1_ConfigurationDownloader()
        {
            ConfigurationDownloader loader = new ConfigurationDownloader();
            loader.ConfigurationDownloadCompleted += new EventHandler<ConfigurationDownloadCompletedArgs>(loader_ConfigurationDownloadCompleted);
            loader.DownloadConfiguration(this.ConfigurationUri);
        }
        void loader_ConfigurationDownloadCompleted(object sender, ConfigurationDownloadCompletedArgs e)
        {
            Debug.WriteLine(e.Result);
            Assert.IsTrue(!String.IsNullOrEmpty(e.Result));
        }

        [TestMethod]
        public void TestMethod2_DownloadConfiguration()
        {
            ConfigurationManager.Instance.ConfigurationFilename = this.ConfigurationUri;
            ConfigurationManager.Instance.ConfigurationDownloadCompleted += new EventHandler<ConfigurationDownloadCompletedArgs>(Instance_ConfigurationDownloadCompleted);
            ConfigurationManager.Instance.DownloadConfiguration();
        }
        void Instance_ConfigurationDownloadCompleted(object sender, ConfigurationDownloadCompletedArgs e)
        {
            Debug.WriteLine(e.Result);
            Assert.IsTrue(!String.IsNullOrEmpty(e.Result));
        }

    }
}